package org.abratuhi.uradar.util;

/**
 * Class to extend the functionality of Java Arrays 
 * @param <T>	-	type of Java Array
 * 
 * 
 * @author Alexei Bratuhin
 * @version 1.00
 */
public class ArrayUtil<T> {
	
	/**
	 * Check, whether the given array contains the given object
	 * @param array			input array
	 * @param object		input object to search
	 * @return				<ul><li>true, if input array contains input object</li>
	 * 						<li>false, otherwise</li></ul> 
	 */
	public boolean contains(T[] array, T object){
		// check NULL
		if(array == null || object == null){
			//System.out.println("ArrayUtil<T> contains(T[] array, T object):\tone or more of parameters is NULL");
			return false;
		}
		// check array size
		if(array.length < 1){
			return false;
		}
		// search
		for(int i=0; i<array.length; i++){
			if(array[i] == object){
				return true;	// case found
			}
		}
		return false;	// case nothing found
	}
	
	/**
	 * find out the position index, at which the given array contains the given object
	 * @param array			input array
	 * @param object		input object to search
	 * @return				<ul><li>position index, if input array contains input object</li>
	 * 						<li>-1, otherwise</li></ul> 
	 */
	public Integer containsAt(T[] array, T object){
		// check NULL
		if(array == null || object == null){
			//System.out.println("ArrayUtil<T> contains(T[] array, T object):\tone or more of parameters is NULL");
			return -1;
		}
		// check array size
		if(array.length < 1){
			return -1;
		}
		// search
		for(int i=0; i<array.length; i++){
			if(array[i] == object){
				return i;	// case found
			}
		}
		return -1;	// case nothing found
	}

}
